#!/usr/bin/env python

FILES = (
    "README.txt", 
    "setup.py", 
    "smokejs"
)

def main(argv=None):
    if argv is None:
        import sys
        argv = sys.argv

    from optparse import OptionParser
    from os import popen
    import fileinput

    parser = OptionParser("usage: %prog NEW_VERSION")

    opts, args = parser.parse_args(argv[1:])
    if len(args) != 1:
        parser.error("wrong number of arguments") # Will exit

    new_version = args[0]
    old_version = popen("./smokejs --version").read().strip()

    print "Changing version from %s to %s..." % (old_version, new_version)
    for line in fileinput.input(FILES, inplace=1):
        print line.replace(old_version, new_version)[:-1]
    print "Done"

if __name__ == "__main__":
    main()

